package com.ruoyi.util;

import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

/**
 * @program: ChainUp_Monitor_Rear
 * @description:
 * @author: Saumell
 * @create: 2024-07-31 17:39
 **/
public class LarkNewRobotUtils {

    private static RestTemplate restTemplate;
    private static final Logger log = LoggerFactory.getLogger(LarkDangerRobotUtils.class);


    static {
        restTemplate = new RestTemplate();
    }

    public static String notice(String value, String robotUrl) {

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("msg_type", "text");
        Map<String, String> map = new HashMap<>();
        map.put("text", value);
        jsonObject.put("content", map);
        ResponseEntity<String> postForEntity = null;
        try {
            postForEntity = restTemplate.postForEntity(robotUrl, jsonObject, String.class);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (postForEntity.getStatusCodeValue() != 200) {
            log.error("飞书报警发送失败,请求参数:{},响应参数:{}", value, postForEntity.getBody());
            return "";
        }
        // 获取http状态码
        int statusCodeValue = postForEntity.getStatusCodeValue();
        log.info("httpCode-----" + statusCodeValue);

        // 获取返回体
        String body = postForEntity.getBody();
        log.info("body-----{}", body);
        log.info("ResponseEntity----" + postForEntity);
        return body;
    }


}
